from sqlalchemy import create_engine, Column, Integer, String, VARCHAR, Float, ForeignKey
from sqlalchemy.orm import DeclarativeBase, sessionmaker

e = create_engine("mysql+pymysql://root:Metro#79@localhost:3306/example?charset=utf8mb4")


class Base(DeclarativeBase):
    pass


class Product(Base):
    __tablename__ = "t_product"
    id = Column(Integer, primary_key=True, autoincrement=True)
    sku = Column(VARCHAR(20), unique=True, nullable=False, comment="商品sku", default="")
    sku_name = Column(VARCHAR(20), nullable=False, comment="商品名称", default="")
    sku_price = Column(Float(20), nullable=False, comment="商品价格", default="")


class Employee(Base):
    __tablename__ = "t_employee"
    id = Column(Integer, primary_key=True, autoincrement=True, comment="主键")
    name = Column(VARCHAR(20), nullable=False, comment="员工姓名")
    email = Column(VARCHAR(50), nullable=True, comment="员工邮箱")
    phone = Column(VARCHAR(11), nullable=False, comment="员工手机号")
    employee_no = Column(VARCHAR(20), comment="员工工号")


def create_tables():
    Base.metadata.create_all(e)


def get_conn():
    session = sessionmaker(bind=e)
    return session(bind=e)
